<?php
namespace App\Http\Controllers\ApiAdmin;

use App\DBs\Stock\BoardDB;
use Illuminate\Http\Request;

class BoardController extends BaseController
{
    /**
     * 库
     */

    protected $db;

    public function __construct()
    {
        parent::__construct();
        $this->db = new BoardDB();
    }

    /**
     * 列表
     */
    public function getIndex(Request $request)
    {
        //接口权限值
        if ($request->adminAccess != $this->adminAccess) {
            return $this->toAppJson(-1);
        }
        //获取参数
        $page = $request->post('page',0);
        $size = $request->post('size',$this->limit);
        $vid = $request->post('vid',0);
        $uid = $request->post('uid',0);
        //梳理数据
        $resDb = $this->db->getAdminIndex($page,$size,$vid,$uid);
//        return $resDb;
        if ($resDb['code']!=0) {
            return $this->toAdminJson(-3);
        }
        $dataArr = $resDb['data'];
        $total = $resDb['total'];
        return $this->toAdminJson(0, $dataArr, $total);
    }

    /**
     * 获取库视频、用户列表
     */
    public function getConditions(Request $request)
    {
        //接口权限值
        if ($request->adminAccess != $this->adminAccess) {
            return $this->toAppJson(-1);
        }
        //梳理数据
        $resDb = $this->db->getAdminCases();
        $resDb2 = $this->db->getAdminUsers();
        $dataArr['stocks'] = $resDb['data'];
        $dataArr['users'] = $resDb2['data'];
        return $this->toAdminJson(0, $dataArr);
    }
}